/**
 *====================================================
 * 文件名称: FinanceAuditLogServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年09月23日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceAuditLogEntity;
import com.yuexunit.finance.project.entity.FinanceCompleteResultEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;


@Implements(FinanceAuditLogService.class)
public class FinanceAuditLogServiceImpl implements FinanceAuditLogService {

	@Override
	public Long createFinanceAuditLogEntity(FinanceAuditLogEntity entity) {
		entity.setCreateDateTime(new Date());
		PersistUtil.insert(entity);
		return entity.getId();
	}

	

	@Override
	public List<FinanceAuditLogEntity> inquireFinanceAuditLogList(Long auditJoinId,Long auditTask) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceAuditLogEntity.class);
		criteria.add(Restrictions.eq("auditJoinId", auditJoinId));
		criteria.add(Restrictions.eq("auditTask", auditTask));
		criteria.addOrder(Order.desc("auditDate"));
		return PersistUtil.get(criteria);
	}



	@Override
	public List<Long> inquireFinAuditLogListByAccount(
			Long accountId,Long auditTask) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceAuditLogEntity.class);
		criteria.add(Restrictions.eq("accountId", accountId));
		criteria.add(Restrictions.eq("auditTask", auditTask));
		criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("auditJoinId")));
		return PersistUtil.get(criteria);
	}
	
	@Override
	public Long createFinanceCompleteResultEntity(FinanceCompleteResultEntity entity) {
		entity.setCreate_dt(new Date());
		PersistUtil.insert(entity);
		return entity.getId();
	}
	
	@Override
	public List<FinanceCompleteResultEntity> checkCompleteResultDate(Long publicId,String tasktype) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceCompleteResultEntity.class);
		criteria.add(Restrictions.eq("publicId", publicId));
		criteria.add(Restrictions.eq("taskType", tasktype));
		return PersistUtil.get(criteria);
	}
	
	@Override
	public List<Long> inquireFinanceCompleteResultList() {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceAuditLogEntity.class);
		criteria.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
		criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("accountId")));
		return PersistUtil.get(criteria);
	}

	@Override
	public void updateFinanceCompleteResultEntity(FinanceCompleteResultEntity entity) {
		PersistUtil.update(entity);
	}
}
